--
-- Author: shunguo.chen
-- Date: 2019-05-16 16:02:00
--
-- LegendRender 神器render
--

local ClassRef = app.mvc.createListViewCell(...)

--data = LegendVo
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.LegendNode))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)

    self:setContentSize(self._ui.Panel:getContentSize())
    self._ui.choose:setVisible(false)

    display.uiAddClick(self._ui.Panel, function()
        if self._data and self._cellModel and not self._cellModel:isFoucs() then
            self:dispatchCellEvent("click", self)
        end
    end)

    self:refresh()
end

function ClassRef:refresh()
    if self._data then
        self:freshBrightStatus()
        
        local data = self._data
        local isActive = data:isActive()

        self._ui.name:setString(data:getName())
        self._ui.tips:setString(data:getSpecName())
        self._ui.lv:setString(isActive and string.format(L("LegendLv"), data.lv) or L("text_11800011"))
        self._ui.equipped:setVisible(data:isWear())
        self._ui.mask:setVisible(not isActive)

        local showFashion = data:getShowFashion()
        self._ui.icon:loadTexture(showFashion:getMidIcon())
    end
end

function ClassRef:freshBrightStatus()
    if self._cellModel then
        self._ui.choose:setVisible(self._cellModel:isFoucs())
    end
end

function ClassRef:onFoucsIndexChange(foucsIndex)
    self:freshBrightStatus()
end

return ClassRef
